%%% Comandos
\newcommand{\ent}[1]{ {\bf #1: } } % Entradillas
\newcommand{\Goal}{\textsc{Goal}}
\newcommand{\Percept}{\textsc{Percept}}
\newcommand{\Action}{\textsc{Action}}

%% Nomenclatura para que todo sea consistente
\newcommand{\AMil}{Military Agent}
\newcommand{\AEcon}{Econ Agent}
\newcommand{\AGen}{General Agent}
\newcommand{\AMov}{Movement Agent}

%%% Definición de entornos %%%
%% Para que no sea un engorro escribir a mano los elementos que tiene que tener
% cada uno de los entornos me he creado unos scripts del vim Latex. Si alguien
% los necesita que me los pida.
%% Functionalities %%
\newenvironment{func}[1]{\noindent \rule{\textwidth}{2pt} {\large{\bf Functionality #1}}
\begin{description} {} 
}
{\end{description}
\rule{\textwidth}{1pt}
}

%% Scenarios %%
\newenvironment{scenario}[1]
{ \noindent \rule{\textwidth}{2pt} {\large {\bf Scenario #1}} \\
}
{
}

%% Plain %% 
\newenvironment{card}[2]
{
\noindent \rule{\textwidth}{2pt} {\large {\bf #1 #2}} \\
}
{
\noindent \rule{\textwidth}{1pt}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Empieza el texto real
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{System Specification}
\label{app:sysSpec}
\subsection{Goal Overview Diagram}
\begin{figure}[htp]
	\begin{center}
		\includegraphics[width=13cm]{images/GoalOverviewDiagram.png}
	\end{center}
	\caption{Goal Overview Diagram}
	\label{fig:goalOverviewDiagram}
\end{figure}

\subsection{Functionalities}
\label{sec:functionalities}

\subsubsection{Functionalities Specification}
\begin{func}{Unit Movement}
\item[Name] Unit movement
\item[Description] This functionality manages moving units when the move through
	the map. Timing, path-finding and coordination are aspects of this
	functionality.
\item[Triggers] Agents with moving units
\item[Actions] Move unit
\item[Information used] Map Description, Known unit position DB
\item[Information produced] Known unit position DB
\item[Goals] Move Unit, Attack, Construct building
\end{func}

\begin{func}{Construction}
\item[Name] Construction 
\item[Description] Knows how to build units and buildings. It builds the
	necessary
	buildings and research to create a given unit
\item[Triggers] A deficit in military units or economic units
\item[Actions] Create building, Build unit 
\item[Information Used] Tech tree definition, Map description
\item[Information Produced] None
\item[Goals] Construct Building, Create Units
\end{func}

\begin{func}{Attack \& Defense}
\item[Name] Attack \& Defense 
\item[Description] Manages all the information related to calculating the combat
	outcomes
\item[Triggers] Enemy units enter the LOS, An attack against the enemy is
	planned
\item[Actions] Attack unit, Create squad, Change attacking behaviour
\item[Information Used] Unit Description DB
\item[Information Produced] Movement orders, Asking for more units
\item[Goals] Attack, Ask for help
\end{func}

\begin{func}{Communication}
\item[Name] Communication 
\item[Description] Creates the protocols for communication and coordination with
	other teammates in the game
\item[Triggers] Enemy units enter the LOS, Enemy Commander spotted
\item[Actions] Send message, Receive message
\item[Information Used] None
\item[Information Produced] Messages
\item[Goals] Communicate, Ask for help
\end{func}

\subsection{Scenarios}
\begin{scenario}{Search for the Enemy Commander}
	\ent{Name} Search for the Enemy Commander (EC) \\
	\ent{Description} The objective of the game is to destroy the opponent's
	commander. This scenario illustrate the set of actions performed to gain
	information about where is the enemy commander. \\
	\ent{Trigger} The belief about the position of the enemy commander is
	inexistent or outdated.
	\begin{table}[htp]
		\rowcolors{1}{gray}{lightgray}
		\centering
		\begin{tabular}{|c|p{.1\textwidth}|p{.2\textwidth}|p{.2\textwidth}|p{.15\textwidth}|p{.2\textwidth}|}
		%\begin{tabular}{|c|l|l|l|l|l|}
			\hline 
			\# & Type & Name & Functionality & Data used & Data produced \\
			1 & \Goal & Build 3 units & Construction & Map state & 3 new units \\
			2 & \Goal & Move unit & Movement & Map state & None \\
			3 & \Percept & Enemy Unit enters the LOS & Attack \& Defense & None & Updated Known Units \\
			\hline
		\end{tabular}
	\end{table}
\end{scenario}

\subsection{Percepts}
%\begin{card}{Percepts}{<++>}
%	\begin{description}
%		\item[Name]<++>
%		\item[Description]<++>
%		\item[Information Carried]<++>
%		\item[Knowledge Updated]<++>
%		\item[Source]<++>
%		\item[Processing]<++>
%		\item[Agents responding]<++>
%		\item[Expected frequency]<++>
%	\end{description}<++>
%\end{card}<++>
\begin{card}{Percepts}{Unit created}
	\begin{description}
		\item[Name] Unit created
		\item[Description] There is a new unit that can be controlled by our
			system.
		\item[Information Carried] The unit type and the position
		\item[Knowledge Updated] Known units database
		\item[Source] SpringRTS
		\item[Processing] None
		\item[Agents responding] The unit is assigned to the General
		\item[Expected frequency] 1 per minute
	\end{description}
\end{card}


\begin{card}{Percept}{Enemy unit enters the LOS}
	\begin{description}
		\item[Name] Enemy unit enters the LOS 
		\item[Description] A unit is close enough for the SprintRTS send to the
system the full description of the unit. The Fog Of War has no effect on
this unit and can be fully determined. 
		\item[Information Carried] The unit type and the position
		\item[Knowledge Updated] Known units database
		\item[Source] SpringRTS
		\item[Processing] None
		\item[Agents responding] The General receives this information and
			reacts according to the perceived threat. 
		\item[Expected frequency] 1 per minute
	\end{description}
\end{card}

\begin{card}{Percepts}{Game starts}
	\begin{description}
		\item[Name] Game starts
		\item[Description] Event for starting the game 
		\item[Information Carried] None
		\item[Knowledge Updated] None
		\item[Source] SpringRTS
		\item[Processing] None
		\item[Agents responding] All
		\item[Expected frequency] Once for game
	\end{description}
\end{card}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Actions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Actions}
\begin{card}{Action}{Move unit}
	\ent{Name} Move unit \\
	\ent{Description} Send the request to the Spring RTS to move a given unit
	to the specified coordinates. \\
\end{card}

\begin{card}{Action}{Create building}
	\ent{Name} Create building  \\
	\ent{Description} Sends the order of starting the construction of a given
	building in a given place. \\
\end{card}

\begin{card}{Action}{Create unit}
	\ent{Name} Create unit \\
	\ent{Description} Queues the order of starting to build a given unit. \\
\end{card}

\begin{card}{Action}{Attack unit}
	\ent{Name} Attack unit \\
	\ent{Description} Selects a unit for receiving the fire power of the stated
	unit. \\
\end{card}

\subsection{Data}
\subsubsection{External}

\paragraph{Map definition}
Contains the static information about the map we are using in the scenario.

\paragraph{Unit definitions}
Contains the specific information about the units present in the game.

\paragraph{Know units DB}
This database maintains an updated collection of the positions, strength and
beliefs of the units that dynamically appear in the game. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Architectural Design}
\label{app:archDesign}
\subsection{System Overview Diagram}
\begin{figure}[htp]
	\begin{center}
		\includegraphics[width=16cm]{images/AnalysisOverviewDiagram.png}
	\end{center}
	\caption{System Overview Diagram}
	\label{fig:systemOverviewDiagram}
\end{figure}

\subsection{Agents}
% Template
%\begin{card}{Agent}{<++>}							
%	\begin{description}							
%		\item[Name] <++>								
%		\item[Description] <++>					
%		\item[Cardinality minimum] <++>			
%		\item[Cardinality maximum] <++>
%		\item[Lifetime] <++>					
%		\item[Initialization] <++>					
%		\item[Demise] <++>								
%		\item[Percepts] <++>					
%		\item[Actions] <++>									
%		\item[Uses data] <++>				
%		\item[Produces data] <++>				
%		\item[Internal data] <++>					
%		\item[Goals] <++>					
%		\item[Functionalities] <++>						
%		\item[Protocols] <++>						
%	\end{description}<++>							
%\end{card}<++>										
\begin{card}{Agent}{General}
	\begin{description}
		\item[Name] General
		\item[Description] This agent balances the various facets of the game.
			It acts as the judge whenever a conflict of interest with agents in
			lower levels arise as it has the big picture of the situation.
		\item[Cardinality minimum] 1
		\item[Cardinality maximum] 1
		\item[Lifetime] All the game
		\item[Initialization] At startup
		\item[Demise] At the end
		\item[Percepts] A enemy unit enters the LOS
		\item[Actions] Build unit, Attack unit
		\item[Uses data]  % TODO
		\item[Produces data] 
		\item[Internal data] 
		\item[Goals] 
		\item[Functionalities] 
		\item[Protocols] 
	\end{description}
\end{card}

\begin{card}{Agent}{Military}
	\begin{description}
		\item[Name] Military Manager
		\item[Description] This agent is responsible of everything related with
			combat. It has the abilities to evaluate a combat situation and
			respond with the best reaction possible
		\item[Cardinality minimum] 1
		\item[Cardinality maximum] 1
		\item[Lifetime] All the game
		\item[Initialization] At startup
		\item[Demise] At the end
		\item[Percepts] Enemy unit at position XY
		\item[Actions] Attack unit, Change attack mode 
		\item[Uses data] Unit description
		\item[Produces data] None
		\item[Internal data] None
		\item[Goals] Attack
		\item[Functionalities] Attack \& Defense
		\item[Protocols] Explore protocol 
	\end{description}
\end{card}

\begin{card}{Agent}{Economy}							
	\begin{description}							
		\item[Name] Econ								
		\item[Description] This agents has the responsibility of creating units
			and buildings
		\item[Cardinality minimum] 1			
		\item[Cardinality maximum] 1
		\item[Lifetime] All the game					
		\item[Initialization] At startup					
		\item[Demise] At the end								
		\item[Percepts] None					
		\item[Actions] Create Building, Create Unit									
		\item[Uses data] Map description				
		\item[Produces data] Known units				
		\item[Internal data] 					
		\item[Goals] Construct Building, Collect Raw Materials, Create Unit					
		\item[Functionalities] Construction						
		\item[Protocols] Create units protocol
	\end{description}							
\end{card}


\begin{card}{Agent}{Movement}							
	\begin{description}							
		\item[Name] Movement Agent								
		\item[Description] This agent is responsible of moving the units in the
			game
		\item[Cardinality minimum] 1			
		\item[Cardinality maximum] 1
		\item[Lifetime] All the game					
		\item[Initialization] At startup					
		\item[Demise] At the end								
		\item[Percepts] None					
		\item[Actions] Move unit									
		\item[Uses data] Map description, Unit description				
		\item[Produces data] None				
		\item[Internal data] 					
		\item[Goals] Move Units					
		\item[Functionalities] Movement						
		\item[Protocols] Move unit protocol						
	\end{description}							
\end{card}


\begin{card}{Agent}{Communication}							
	\begin{description}							
		\item[Name] Communication Agent								
		\item[Description] This agent is responsible of communicating with other
			teammates. Its main responsibility is to control the communication
			channel and to filter which messages are sent to the General.
		\item[Cardinality minimum] 1			
		\item[Cardinality maximum] 1
		\item[Lifetime] All the game 
		\item[Initialization] At startup
		\item[Demise] At the end								
		\item[Percepts] None				
		\item[Actions] None									
		\item[Uses data] None				
		\item[Produces data] None				
		\item[Internal data] None					
		\item[Goals] Communicate, Ask for help					
		\item[Functionalities] Communication						
		\item[Protocols] Ask for help protocol						
	\end{description}							
\end{card}										



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Protocols
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{card}{Protocol}{}
%	\begin{description}
%		\item[Name]<++>
%		\item[Description]<++>
%		\item[Included messages]<++>
%		\item[Scenarios]<++>
%		\item[Agents]<++>
%		\item[Notes]<++>
%	\end{description}<++>
%\end{card}<++>

\subsection{Protocols}
\label{sec:Protocols}

%\begin{card}{Protocol}{<++>}
%	\begin{description}
%		\item[Name] <++>
%		\item[Description] <++>
%		\item[Included messages] <++>
%		\item[Scenarios] <++>
%		\item[Agents] <++> → <++>
%		\item[Notes] <++>
%	\end{description}
%\end{card}

\begin{card}{Protocol}{Create unit protocol}
	\begin{description}
		\item[Name] Create unit protocol 
		\item[Description] Defines the communication between the General and the
			Econ when the general is interested on building some units.
		\item[Included messages] Create Unit
		\item[Scenarios] Search for the Enemy Commander
		\item[Agents]  General → Econ
		\item[Notes]
	\end{description}
\end{card}

\begin{card}{Protocol}{Explore protocol}
	\begin{description}
		\item[Name] Explore
		\item[Description] Defines the regions in which the General is
			interested to be explored. 
		\item[Included messages] Explore region
		\item[Scenarios] Search for the Enemy Commander
		\item[Agents] General → Military
		\item[Notes] 
	\end{description}
\end{card}

\begin{card}{Protocol}{Move Unit protocol}
	\begin{description}
		\item[Name] Move Unit
		\item[Description] The protocol necessary to move units around the map
		\item[Included messages] Move Unit Message
		\item[Scenarios] Search for the Enemy Commander
		\item[Agents] Military → Movement, Econ → Movement
		\item[Notes] 
	\end{description}
\end{card}

\begin{card}{Protocol}{Ask for Help protocol}
	\begin{description}
		\item[Name] Ask for help protocol
		\item[Description] This is the protocol where the General coordinates
			the communication with team mates to receive some help when
			attacked.
		\item[Included messages] Ask for Help Message
		\item[Scenarios] Search for the Enemy Commander
		\item[Agents] General → Communications
		\item[Notes] 
	\end{description}
\end{card}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Messages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{card}{Message}{<++>}
%	\begin{description}
%		\item[Name] <++>
%		\item[Description] <++>
%		\item[Distribution] <++>
%		\item[Purpose] <++>
%		\item[Carried information] <++>
%	\end{description}<++>
%\end{card}<++>

\subsection{Messages}
\begin{card}{Message}{Build units}
	\begin{description}
		\item[Name] Build units
		\item[Description] Issues the order to create more units of a given type
		\item[Distribution] General → Econ Agent 
		\item[Purpose] To send the Econ Agent the order of building more units
			and the necessary buildings and resource extractors
		\item[Carried information] Both the type of unit and the number of units
	\end{description}
\end{card}

\begin{card}{Message}{Explore region}
	\begin{description}
		\item[Name] Explore region
		\item[Description] Asks the Military Agent to explore a given region to
			update the Database of Know Units
		\item[Distribution] General → Military Agent
		\item[Purpose] This message tells the Military Agent to send the best
			unit assigned to it to explore the specified region and to update
			the Known Units Database
		\item[Carried information] The region to be explored
	\end{description}
\end{card}

\begin{card}{Message}{Move Unit}
	\begin{description}
		\item[Name] Move Unit Message
		\item[Description] The order to move a unit in a 2D environment
		\item[Distribution] Military → Movement, Econ → Movement
		\item[Purpose] To specify clearly how the movement has to be performed
		\item[Carried information] The end position, special considerations when
			moving the units
	\end{description}
\end{card}

\begin{card}{Message}{Ask for Help Message}
	\begin{description}
		\item[Name] Ask for Help Message
		\item[Description] This message contains the information of the
			necessary help that is requested and all the consequent negotiation
			that could be needed
		\item[Distribution] General  → Communication
		\item[Purpose] Ask for help when a major threat can not be dealt by the
			artificial player
		\item[Carried information] The message for help, the possible
			negotiations
	\end{description}
\end{card}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Detailed Design
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Detailed Design}
\label{app:detDesign}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% General
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Agent General}
\subsubsection{Processes}
\begin{figure}[htp]
	\begin{center}
		\includegraphics[width=5cm]{images/Proceso.png}
	\end{center}
	\caption{Search the Enemy Commander Process}
	\label{fig:Proceso}
\end{figure}

